#include <iostream>
#include <cmath>
#include <string>
using namespace std;
int main()
{
    string convert;
    int s,s1, n, summ,stor,trig1,trig0,res1,res0= 0;
    int l = 100;
    int a[3];
    for(int i = 0; i<3; i++){
        cin >> convert;
        if(convert == "zero"){
            a[n] = 0;
        }
        else if(convert == "one") {
            a[n] = 1;
        }
        else if(convert == "two") {
            a[n] = 2;
        }
        else if(convert == "three") {
            a[n] = 3;
        }
        else if(convert == "four") {
            a[n] = 4;
        }
        else if(convert == "five") {
            a[n] = 5;
        }
        else if(convert == "six") {
            a[n] = 6;
        }
        else if(convert == "seven") {
            a[n] = 7;
        }
        else if(convert == "eight") {
            a[n] = 8;
        }
        else if(convert == "nine") {
            a[n] = 9;
        }
        else {
            cout << "Wrong input";
            return 0;
        }
        n++;
    }
    n = 0;
    for(int i = 0; i<3;i++){
        summ = summ + a[n]*l;
        l = l/10;
        n++;
    }
    n = 0;
    
    stor = summ;
    
    while (trig0!=1){
        for(int i = 1; i<stor+1;i++){
            if (stor%i==0){
                res0 = stor;
                s++;
            }
        }
        if (s==2){
            res0=stor;
            trig0++;
        }
        else if (s<2){
            res0=2;
            trig0++;
        }
        else {
            stor--;
            s = 0;
            }
        } 
    stor=summ;
    while (trig1!=1){
        for(int i = 1; i<999;i++){
            if (stor%i==0){
                res1 = stor;
                s1++;
            }
        }
        if (s1==2){
            res1=stor;
            trig1++;
        }
        else if (s1<2){
            res1=2;
            trig1++;
        }
        else {
            stor++;
            s1 = 0;
            }
        }
    if (fabs(summ-res0)<=fabs(summ-res1)) {
        cout<<res0;
    }
    else if (fabs(summ-res0)>fabs(summ-res1)) {
        cout<<res1;
    }
    else{
        cout<<2;
    }
    return 0;
}
